<template>
  <div class="profile">
    <el-row :gutter="20" style="justify-content:center">
      <el-col :md="24" :sm="8">
        <el-card class="box-card">
          <div>
            <div class="text-center">
              <userAvatar :user="user" />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <i class="el-icon-user-solid">  用户名称</i>
                <div class="pull-right">{{ user.userName }}</div>
              </li>
              <li class="list-group-item">
                <i class="el-icon-user">  用户姓名</i>
                <div class="pull-right">{{ user.nickName }}</div>
              </li>
              <li class="list-group-item">
                <i class="el-icon-mobile-phone">  手机号码</i>
                <div class="pull-right">{{ user.phonenumber }}</div>
              </li>
              <li class="list-group-item">
                <i class="el-icon-message">  用户邮箱</i>
                <div class="pull-right">{{ user.email }}</div>
              </li>
              <li class="list-group-item">
                <i class="el-icon-office-building">  所属部门</i>
                <div class="pull-right">{{ deptGroup }}</div>
              </li>
              <li class="list-group-item">
                <i class="el-icon-postcard">  所属岗位</i>
                <div v-if="postGroup" class="pull-right"> {{ postGroup }}</div>
              </li>
              <li class="list-group-item">
                <i class="el-icon-s-custom">  所属角色</i>
                <div class="pull-right">{{ roleGroup }}</div>
              </li>
              <li class="list-group-item">
                <i class="el-icon-date">  创建日期</i>
                <div class="pull-right">{{ user.createTime }}</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userAvatar from './UserAvatar'
import { getUserProfile } from '@/api/system/user'

export default {
  name: 'Profile',
  components: { userAvatar },
  data() {
    return {
      user: {},
      roleGroup: {},
      postGroup: {},
      deptGroup: {},
      activeTab: 'userinfo'
    }
  },
  created() {
    this.getUser()
    this.activeTab = this.$route.query.activeTab || 'userinfo'
  },
  methods: {
    getUser() {
      getUserProfile().then(response => {
        const extData = response.extData || {}
        this.user = response.data
        this.roleGroup = extData.roleGroup
        this.postGroup = extData.postGroup
        this.deptGroup = extData.deptGroup
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.profile {
  .text-center {
    text-align: center
  }
  .list-group-striped > .list-group-item {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    padding-left: 0;
    padding-right: 0;
  }

  .list-group {
    padding-left: 0px;
    list-style: none;
  }

  .list-group-item {
    margin-bottom: 16px;
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    font-size: 13px;
  }

  .pull-right {
    flex: 1;
    margin-left: 20px;
  }
}
</style>
